<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/11/2
 * Time: 16:09
 */

namespace app\api\model;


class CardAudio extends BaseModel
{
    protected $autoWriteTimestamp = true;
    protected $hidden=['from','create_time','delete_time'];

    public function getUrlAttr($value,$data){
        return $this->prefixAudio($value,$data);
    }

    /**
     * 创建音频
     * @param $info
     * @return $this
     */
    public static function createImg($info)
    {
        $data = [
            'name'=>$info->fname,
            'url'=>$info->fkey,
            'key'=>$info->fkey,
            'from'=>2
        ];
        $num =  (new CardAudio())->insertGetId($data);
        $result = self::get($num);
        return $result;
    }

    /**
     * 更新音频
     * @param $data
     * @return BaseModel
     */
    public static function updateImg($info)
    {
        $data = [
            'url'=>$info->items[0]->key,
            'key'=>$info->items[0]->key,
            'from'=>2
        ];
        $result = self::where('url','=',$info->inputKey)->update($data);
        return $result;
    }


    /**
     *获取音频
     * @param $img_id
     * @return null|static
     */
    public static function getImg($img_id){
        return self::get($img_id);
    }
    /**
     * 删除音频
     * @param $img_id
     * @return int
     */
    public static function deleteImg($img_id){
        return self::destroy($img_id);
    }
}